package server;

import java.util.HashMap;

/**
 * 
 * A class of all the message strings passed between the client and user
 * This is used for clarity and consistency
 *
 */
public class Message {

	//login commands
	public static String loginRequest(String username){
		return "login(" + username + ")";
	}
	
	public static String loginSuccessful(String username){
		return "login successful!" + username;
	}
	
	public static String userDoesNotExist(){
		return "user does not exist";
	}

	
	
	//sign up commands

	
	public static String userAlreadyExists(){
		return "user already exists";
	}
	
	//log out commands
	public static String logOutRequest(String username){
		return "logOut(" + username + ")";
	}
	
	public static String logOutSuccessful(){
		return "log out successful";
	}
	
	public static String logOutFail(){
		return "log out fail";
	}
/*	
	// buddylist retrieval commands
	public static String getBL(String username){
		return "getBuddyList(" + username + ")";
	}

	public static String getBLSuccess(BuddyList bl){
		String BLString = "getBLSuccess";
		for (Group g : bl.getGroups()) {
			BLString = BLString + g.toString() + "=";
			for (String s : g.getMembers()) {
				String status = Server.RegUserMap.get(s).getStatus();
				BLString = BLString + s + " " + status + ",";
			}
			BLString = BLString + "|";
		}
		return BLString;
	}
	
	public static String getBLFailure(){
		return "get buddy list failure";
	}
	
*/	


	// chat message commands : can be used for chat and chatroom
	public static String chatMessage(String sender, String text){
		return "chatMessage(" + sender  + "%" + text + ")";
	}
	
	public static String chatMessageSuccess(String username, String text) {
		return "chat message successful!" + username + "%" + text;
	}
	
	public static String chatMessageFailure(String username) {
		return "chat message failure!" + username;
	}
	
	public static String select(String stackName, String draggerName)
	{
		return "select(" + stackName + "," + draggerName + ")";
	}
	
	public static String selectSuccess()
	{
		return "select success";
		
	}
	
	public static String selectFailure()
	{
		return "selectFailure";
	}
	
	
	public static String startDrag(String stackName, String draggerName)
	{
		return "startDrag(" + stackName + "," + draggerName + ")";
	}
	
	public static String startDragSuccessful()
	{
		return "startDragSuccessful";
	}
	
	public static String startDragFailure()
	{
		return "startDragFailure";
	}
	
	public static String dragging(String stackName, int x, int y, String draggerName)
	{
		return "dragging(" + stackName + "," + x + "," + y + "," + draggerName + ")";
	}
	
	public static String drop(String stackName, int x, int y, String draggerName)
	{
		return "drop(" + stackName + "," + x + "," + y + "," + draggerName + ")";	
	}
	
	public static String dropSuccessful()
	{
		return "drop successful";
	}
	
	public static String dropFailure()
	{
		return "drop failure";
	}
	
	public static HashMap<String, String> parseRPC(String msg)
	{
		HashMap<String, String> map = new HashMap<String, String>();
		
		String[] msgStr = msg.split("(");
		
		map.put("function", msgStr[0]);
		
		String[] params = msgStr[1].split("|");
		
		for (int i = 0; i < params.length; i++ )
		{
			String[] keyval = params[i].split("=");
			map.put(keyval[0], keyval[1]);
		}
		
		return map;
	}
	
	//parseCard()
	//parseCardStack()
	//parseStackFragment()

}

